import * as mongoose from 'mongoose';

export const EmployeeSchema = new mongoose.Schema({
  corpId: { type: String, index: true },
  userId: { type: String, index: true },
  name: String,
  englishName: String,
  department: { type: mongoose.Schema.Types.Mixed, required: false }, // 员工所属部门id列表
  order: { type: Number, required: false }, // 排序字段，越小越靠前
  position: String,
  mobile: String,
  gender: String, // 性别：1表示男性，2表示女性
  email: String,
  bizMail: String, // 员工个人企业邮箱
  avatar: String, // 头像url
  status: String, // 帐号激活状态: 1=已激活，2=已禁用，4=未激活，5=退出企业
  isLeader: { type: Boolean, default: false }, // 是否为管理员
  isLeaderInDept: { type: Boolean, default: false }, // 是否为上级
  enable: { type: Boolean, default: true }, // 是否启用
  hideMobile: { type: Boolean, default: false }, // 是否隐藏
  extattr: { type: mongoose.Schema.Types.Mixed, required: false }, // 扩展属性
  joinedAt: Date, // 加入时间
  teamId: Number,
  create_time: { type: Number, default: () => Date.now() },
  update_time: { type: Number, default: () => Date.now() },
}, {
  collection: 'employees',
  timestamps: { currentTime: () => Date.now() }
});

// 添加索引
EmployeeSchema.index({ corpId: 1 });
EmployeeSchema.index({ userId: 1 });
EmployeeSchema.index({ corpId: 1, userId: 1 }, { unique: true });
EmployeeSchema.index({ status: 1 });
EmployeeSchema.index({ mobile: 1 });
EmployeeSchema.index({ email: 1 });
EmployeeSchema.index({ create_time: -1 });